package com.westcom.vulb.logic;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.json.JSONArray;

import com.westcom.vulb.network.http.VulbHttp;
import com.westcom.vulb.protocal.http.Response;
public class BasicLogic 
{
	
	public static String protocol = "http";
	public static String host = "://test.komugi-office.com:";
	public static int port = 8080;
	public static String root_path = "/knowledge/";
	/*
	public static String protocol = "https";
	public static String host = "://vulb.jp:";
	public static int port = 8443;
	public static String root_path = "/knowledge/";
	*/
	public static String base_url = protocol+host+port+root_path;
	
	protected Header[] buildHeader(String sessionId)
    {
    	List <Header> h = new ArrayList<Header>();
    	if(sessionId != null && !sessionId.equals(""))
    	{
    		h.add(new BasicHeader("vssid",sessionId));
    	}
    	h.add(new BasicHeader("device","android"+android.os.Build.VERSION.RELEASE));
    	h.add(new BasicHeader("timezone",null));
    	Header[] ret = new Header[h.size()];
    	h.toArray(ret);
    	return ret;
    }
	protected JSONArray intArray2JSONArray(int[] in)
	{
		if(null == in)
		{
			return null;
		}
		JSONArray ja = new JSONArray();
		for(int i:in)
		{
			ja.put(i);
		}
		return ja;
	}
	
	public static HashMap<String, Object> request(String url, HashMap<String, Object> params) {
	    Response response = VulbHttp.post2(url, params);
	    
	    if (response.errno == Response.SUCCESS) {
	        return response.data;
	    }
	    
	    //TODO process error
	    return (new HashMap<String, Object>());
	}
	protected JSONArray StringArray2JSONArray(String[]in)
	{
		if(null == in)
		{
			return null;
		}
		JSONArray ja = new JSONArray();
		for(String i:in)
		{
			ja.put(i);
		}
		return ja;
	}
}
